/**
 * Copyright (c) 2010 - 2012, Sina Inc. All rights reserved.
 * @fileoverview    创建专题
 * @author bowen liu
 * @email liubowen082@163.com
 * @version 1.0
 */

//引用配置文件
//$require('cpt.LJSDefine');
//$require('cpt.collectionTop');

$require('cpt.LJSDefine');
$require('form.cFormTitle');
$require('form.cFormTextarea');
$require('cpt.uploadPic');
$require('form.cFormUrl');
//$require('mod.uploadFlv');
LJS.define('page.createSubiect',function(ljs){
    $('#createSubjectBox')[0].reset();
	var cFormTitle = new ljs.form.cFormTitle({
            'el': $.sizzle('input[form_type=title]')[0],
			'arrow':'down',
            'require': ['focus', 'blur']
        });
	
	var cFormTextarea = new ljs.form.cFormTextarea({
            'el': $.sizzle('textarea[form_type=textarea]')[0],
			'arrow':'down',
            'require': ['focus', 'blur']
        });
	
	var cformUrl = new ljs.form.cFormUrl({
										 'el':$.sizzle('input[form_type=url]')[0],
										 'require':['focus','blur']
										 })
//	var upload = new ljs.mod.uploadFlv({
//									   box : $('[node_type="btn"]')[0],
//									   objectName : 'window._upload'
//									   })
//	window._upload = upload;
//	upload.create()
	var upload = new ljs.cpt.uploadPic({uploadBox:$('#createSubjectBox'),uploadForm : '[node_type="form"]'});
	//uploadSuc
	$(upload).on('uploadSuc',function(evt,data){
							    var _data = data.content[0]
								$('#uploadImg').attr('src',_data.url)
								$('#uploadImgId').val(_data.id)
								$('#uploadError').hide()
									  })
	$(upload).on('uploadErr',function(evt,data){
							    $('#uploadError').show().find('span').html(data.msg)
								$('#uploadImg').attr('src',$('#uploadImg').attr('defSrc'))
								$('#uploadImgId').val('')
									  })
	
	$('#submitBtn').on('click',function(){
										$('#createError').hide();
										if(!cFormTitle.check()){
											$('#createError').show();
											cFormTitle.showError()
											return
											}
										
										if(!cFormTextarea.check()){
											$('#createError').show();
											cFormTextarea.showError()
											return
											}
									    if(!cformUrl.check()){
											$('#createError').show();
											cformUrl.showError()
											return
											}
									    
										if($.trim($('#uploadImgId').val())==''){
											$('#createError').show();
											return
											}
										$('#createSubjectBox').submit();
										
										})
	
})

